import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  OneToMany,
  OneToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { EnterpriseBackground } from './enterprise-background.entity';
import { Industry } from './industry.entity';
import { Patent } from './patent.entity';
import { Trademark } from './trademark.entity';
import { Executive } from './executive.entity';
import { Favorite } from './favorite.entity';

@Entity({
  name: 'enterprise',
})
export class Enterprise {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    length: 255,
    comment: '企业名称',
  })
  name: string;

  @Column({
    length: 100,
    name: 'registration_no',
    comment: '工商注册号',
  })
  registrationNo: string;

  @Column({
    length: 100,
    name: 'legal_representative',
    comment: '法定代表人',
  })
  legalRepresentative: string;

  @Column({
    type: 'int',
    name: 'registered_capital',
    comment: '注册资本',
  })
  registeredCapital: number;

  @Column({
    length: 100,
    name: 'registered_address',
    comment: '注册地址',
  })
  registeredAddress: string;

  @Column({
    length: 100,
    name: 'operation_status',
    comment: '经营状态',
  })
  operationStatus: string;

  @Column({
    type: 'timestamp',
    name: 'establish_time',
    comment: '成立时间',
  })
  establishTime: Date;

  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
  })
  createTime: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
  })
  updateTime: Date;

  @OneToOne(() => EnterpriseBackground, (background) => background.enterprise, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  background: EnterpriseBackground;

  @ManyToMany(() => Industry, (industry) => industry.enterprises, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinTable()
  industries: Industry[]; // 企业所属的行业

  @OneToMany(() => Patent, (patent) => patent.enterprise)
  patents: Patent[];

  @OneToMany(() => Trademark, (trademark) => trademark.enterprise)
  trademarks: Trademark[];

  @OneToMany(() => Executive, (executive) => executive.enterprise)
  executives: Executive[];

  @OneToMany(() => Favorite, (favorite) => favorite.enterprise)
  favorites: Favorite[];
}
